package com.miyake.dsp.otdr.ui;

import java.awt.Component;
import java.awt.FlowLayout;

import com.miyake.dsp.otdr.OtdrSetting;
import com.miyake.dsp.ui.DspTextField;
import com.miyake.dsp.ui.DspWidget;

public class OtdrPropertyPanel extends AbstractOtdrPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4539635456035620704L;
	private OtdrSetting properties;
	private DspTextField wave;
	private DspTextField dist;
	
	public OtdrPropertyPanel(OtdrSetting prop) {
		this.properties = prop;
		initialize();
	}

	private void initialize() {
		this.setLayout(new FlowLayout());
		add(createDistanceRange());
		add(createWavelength());
	}

	private Component createWavelength() {
		wave = new DspTextField("Wavelength");
		wave.setValue(String.valueOf(properties.getWavelength()));
		wave.addHandler(new DspWidgetHandler() {
			@Override
			public void onChange(String value) {
				properties.setWavelength(Double.valueOf(value));
				fireChange(value);
			}
		});
		return wave;
	}

	private DspTextField createDistanceRange() {
		dist = new DspTextField("Distance Range");
		dist.setValue(String.valueOf(properties.getDistanceRange()));
		dist.addHandler(new DspWidgetHandler() {
			@Override
			public void onChange(String value) {
				properties.setDistanceRange(Double.valueOf(value));
				fireChange(value);
			}
		});
		return dist;
	}

	@Override
	protected void apply() {
		properties.setDistanceRange(dist.getValue());
		properties.setWavelength(wave.getValue());
	}
}
